package com.distortiongames.elysium.components 
{
	import com.distortiongames.elysium.math.Vector2D;
	import com.pblabs.core.PBComponent;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author Jefferson Wagner
	 */
	public class MouseFollowComponent extends PBComponent 
	{
		[Inject]
		public var stage:Stage;
		
		private var _position:Vector2D = new Vector2D(0, 0);
		
		public function get position():Vector2D 
		{
			return _position;
		}
		
		public function set position(value:Vector2D):void 
		{
			_position = value;
		}
		
		override protected function onAdd():void 
		{
			super.onAdd();
			stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
		}
		
		protected function onMouseMove(event:MouseEvent) : void {
			_position.x = event.stageX;
			_position.y = event.stageY;
		}
		
		override protected function onRemove():void 
		{
			super.onRemove();
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
		}
	}

}